package de.tabuma.wsdl2xform.lib;

import java.util.regex.*;
import java.util.logging.*;

/**
 *
 * @author $Author: alefen $
 * @version $Revision: 1.2 $
 * @since $Date: 2009/07/21 20:00:57 $
 */
public class standardPattern {

    private static Logger log = Logger.getLogger(standardPattern.class.getName());

    private final static Pattern patternName = Pattern.compile("[a-zA-ZöÖäÄüÜß||\\-||\\s]*");
    private final static Pattern patternStreat = Pattern.compile("[a-zA-ZöÖäÄüÜß||\\-||\\s]*");
    private final static Pattern patternHousenumber = Pattern.compile("[\\w\\s]*");
    private final static Pattern patternZipcode = Pattern.compile("[\\d]*");
    private final static Pattern patternCity = Pattern.compile("[a-zA-ZöÖäÄüÜß||\\-||\\s]*");
    private final static Pattern patternEmail = Pattern.compile("[\\w|\\.|-]+@\\w[\\w|-]*\\.[a-z]{2,3}");
    private final static Pattern patternInternet = Pattern.compile("[\\w]*\\.[\\w]*\\.[\\w]*");
    private final static Pattern patternTelefon = Pattern.compile("\\d*[\\d\\s\\-]*");
    private final static Pattern patternCountry = Pattern.compile("[a-zA-ZöÖäÄüÜß||\\-||\\s]*");

    /**
     * Checking whether str is a String with pattern for name
     * @param str
     * @return true or false
     */
    public static boolean isName(String str) {
        if(patternName.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternName.pattern());
            return true;
        }
        log.finest(str + " does not match for pattern "+patternName.pattern());

        return false;
    }

    /**
     * Checking whether str is a String with pattern for streat
     * @param str
     * @return true or false
     */
    public static boolean isStreat(String str) {
        if(patternStreat.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternStreat.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternStreat.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for housenumber
     * @param str
     * @return true or false
     */
    public static boolean isHouseNumber(String str) {
        if(patternHousenumber.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternHousenumber.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternHousenumber.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for zipcode
     * @param str
     * @return true or false
     */
    public static boolean isZipcode(String str) {
        if(patternZipcode.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternZipcode.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternZipcode.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for city
     * @param str
     * @return true or false
     */
    public static boolean isCity(String str) {
        if(patternCity.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternCity.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternCity.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for email
     * @param str
     * @return true or false
     */
    public static boolean isEmail(String str) {
        if(patternEmail.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternEmail.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternEmail.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for internet
     * @param str
     * @return true or false
     */
    public static boolean isInternet(String str) {
        if(patternInternet.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternInternet.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternInternet.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for telefonnumber
     * @param str
     * @return true or false
     */
    public static boolean isTelefonnumber(String str) {
        if(patternTelefon.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternTelefon.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternTelefon.pattern());
        return false;
    }

    /**
     * Checking whether str is a String with pattern for country
     * @param str
     * @return true or false
     */
    public static boolean isCountry(String str) {
        if(patternCountry.matcher(str).matches()) {
            log.finest(str +" matches for pattern "+patternCountry.pattern());
            return true;
        }
        log.finest(str +" does not match for pattern "+patternCountry.pattern());
        return false;
    }
}
